﻿using System;

using SBPweb.Forge.Modules.Modularity;

namespace SBPweb.Forge.Modules.Communication
{
	/// <summary>
	/// Class of RequestObjectMessage
	/// </summary>
	/// <typeparam name="T"></typeparam>
    public class RequestObjectMessage<T> : MessageBase, IRequestMessage<T>
    {

        #region Private fields

        private T response;

        #endregion

        #region Constructor logic

		/// <summary>
		/// Requests object message
		/// </summary>
		/// <param name="sender">sender</param>
		/// <param name="text">text</param>
        public RequestObjectMessage(IModule sender, string text)
            : base(sender, text)
        {
        }

        #endregion

        #region Property accessors

		/// <summary>
		/// Response
		/// </summary>
        public T Response
        {
            get
            {
                return response;
            }
            set
            {
                response = value;
                if (Respond != null)
                {
                    Respond(sender, new RequestMessageEventArgs<T>(this));
                }
            }
        }

        #endregion

        #region Event handlers

		/// <summary>
		/// Event handler of Respond
		/// </summary>
        public event EventHandler<RequestMessageEventArgs<T>> Respond;

        #endregion

    }
}